<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        canvas {
            border: 1px solid #ccc;
        }
    </style>
</head>
<body>
<canvas width="600" height="400"></canvas>
<script>
    var myCanvas = document.querySelector('canvas');
    var ctx = myCanvas.getContext('2d');
    /*绘制坐标系*/
    /*1.确定原点*/
    /*2.确定距离画布旁边的距离*/
    /*3.确定坐标轴的长度*/
    /*4.确定箭头大小 是个等腰三角形 10*/
    /*5.绘制箭头 填充*/

    var space = 20;
    var arrowSize = 10;

    /*计算原点*/
    var canvasWidth = ctx.canvas.width;
    var canvasHeight = ctx.canvas.height;

    var x0 = space;
    var y0 = canvasHeight - space;

    /*绘制X轴*/
    ctx.beginPath();
    ctx.moveTo(x0,y0);
    ctx.lineTo(canvasWidth-space,y0);
    ctx.stroke();
    /*箭头*/
    ctx.lineTo(canvasWidth-space-arrowSize, y0 + arrowSize / 2);
    ctx.lineTo(canvasWidth-space-arrowSize, y0 - arrowSize / 2);
    ctx.lineTo(canvasWidth-space,y0);
    ctx.fill();

    /*绘制Y轴*/
    ctx.beginPath();
    ctx.moveTo(x0,y0);
    ctx.lineTo(x0,space);
    ctx.stroke();
    /*箭头*/
    ctx.lineTo(space + arrowSize / 2 , space + arrowSize);
    ctx.lineTo(space - arrowSize / 2 , space + arrowSize);
    ctx.lineTo(x0,space);
    ctx.fill();
</script>
</body>
</html>
